$(function() {

	//获取字符串长度 正文字符占两字节
	function strlength(str){
    	var len = 0;
    	for (var i=0; i<str.length; i++) { 
     		var c = str.charCodeAt(i); 
     		if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) { 
       			len++; 
     		}else { 
      			len+=2; 
     		} 
    	} 
    	return len;
	}


	//添加菜单
	$('.js_addL1Btn').on('click', function() {

		$('.frm_control_group,.menu_content_container,#saveMenu,.tools_box,.menu_set_area').show();
		//隐藏子菜单、提示
		$('.warning,.js_l2TitleBox,#js_innerNone').hide();

		$("#menuList").removeClass("no_menu");
		//移除样式
		$("li.jsMenu").removeClass("current selected");
		
		//获取当前时间戳
		var times = new Date().getTime();
		//获取菜单长度
		var menuLength = $('.pre_menu_item').length;

		$(".js_addMenuBox_root").before('<li class="jsMenu jslevel1 pre_menu_item grid_item ui-sortable ui-sortable-disabled selected current" id="'+times+'_menu_'+menuLength+'" data-type="1"><a href="javascript:void(0);" class="pre_menu_link" draggable="false"><i class="icon_menu_dot js_icon_menu_dot dn" style="display: none;"></i><i class="icon20_common sort_gray"></i><span class="js_l1Title">菜单名称</span></a><div class="sub_pre_menu_box js_l2TitleBox" style=""><ul class="sub_pre_menu_list"><li class="js_addMenuBox"><a href="javascript:void(0);" class="jsSubView js_addL2Btn" title="最多添加5个子菜单" draggable="false"><span class="sub_pre_menu_inner js_sub_pre_menu_inner"><i class="icon14_menu_add"></i></span></a></li></ul><i class="arrow arrow_out"></i><i class="arrow arrow_in"></i></div></li>');

		//更改页面
		$('#platform').show();//显示菜单设置项
		//url从图文中选中
		$('#edit,#url').hide();
		$('.tab_nav').removeClass('selected');

		//显示消息设置 默认为图文
		$('.tab_nav').removeClass('selected');
		$('.tab_nav:first-child').addClass('selected');
		$('.tab_content,.show_place,.media_del').hide();
		$('.tab_content:first-child,.media_cover').show();
		$('.show_place').html('<div class="waiting"><i class="am-icon-refresh am-icon-spin am-icon-md"></i> 上传中,请稍候</div>');


		$('#jsDelBt').text('删除菜单');
        $('.global_info').text('菜单名称');
        $('.js_menuTitle').text('菜单名称');
        $('.js_menuContent').text('菜单内容');
        $('.js_titleNolTips').show();//提示4个中文或8个字符
        $('.js_titleNolTipsSubButton').hide();
        $('.js_menu_name').val('菜单名称').focus().select();

        button[times+'_menu_'+menuLength] = {};
        button[times+'_menu_'+menuLength]['name'] = '菜单名称';
        button[times+'_menu_'+menuLength]['type'] = 'index';
        button[times+'_menu_'+menuLength]['sub_button'] = {};
        button[times+'_menu_'+menuLength]['url'] = '';
        button[times+'_menu_'+menuLength]['key'] = '';
       
        key[times+'_menu_'+menuLength] = {};
        key[times+'_menu_'+menuLength]['indextype'] = '';

		//附加到删除按钮 菜单类型 1为菜单 2为子菜单
        $('#jsDelBt').attr('data-id',times+'_menu_'+menuLength).attr('data-type',1);
   
        //默认选中平台模块
        $('input[name=docInlineRadio][type=radio]').prop('checked',false);
	    $('input[name=docInlineRadio][type=radio][value=index]').prop('checked',true);
	    //移除选中
	    $('input[name=platform][type=radio]').prop('checked',false);

		//修改宽度
		if($("#menuList").children().length == 4){
			$("li.jsMenu").addClass("size1of"+($("#menuList").children().length-1))
			$(this).parent().hide();
		}else{
			$("li.jsMenu").addClass("size1of"+($("#menuList").children().length))
		}
	});


	//添加子菜单
	$('#menuList').on('click','.js_addL2Btn',function(){
		//更改页面
		$('.warning').hide();
		$('.menu_set_area,#saveMenu,.frm_control_group,.menu_content_container').show();

		var menuBox_root_id = $(this).parent().parent().parent().parent('li').attr('id');
		var menuTimes = new Date().getTime();
		var id = menuTimes+"_subMenu_"+menuBox_root_id;
		
		//移除样式
		$(".jslevel2,.jslevel1").removeClass("current selected");
		//添加子菜单
		$(this).parent('.js_addMenuBox').before('<li class="jslevel2 selected current jsSubMenu" id="'+id+'" data-type="2"><a href="javascript:void(0);"><span class="js_l2Title">子菜单名称</span></a></li>');
		
		$('#platform').show();//显示菜单设置项
		$('#edit,#url').hide();

		//显示消息设置 默认为图文
		$('.tab_nav').removeClass('selected');
		$('.tab_nav:first-child').addClass('selected');
		$('.tab_content,.show_place,.media_del').hide();
		$('.tab_content:first-child,.media_cover').show();
		$('.show_place').html('<div class="waiting"><i class="am-icon-refresh am-icon-spin am-icon-md"></i> 上传中,请稍候</div>');

		$('#jsDelBt').html('删除子菜单');
	    $('.global_info').html('子菜单名称');
	    $('.js_menuTitle').html('子菜单名称');
	    $('.js_menuContent').html('子菜单内容');
	    $('.js_titleNolTips').hide();
        $('.js_titleNolTipsSubButton').show();
		$('.js_menu_name').val('子菜单名称').focus().select();

	    //设置子菜单   
		button[menuBox_root_id]['sub_button'][id] = {};
        button[menuBox_root_id]['sub_button'][id]['name'] = '子菜单名称';
       	button[menuBox_root_id]['sub_button'][id]['key'] = '';
        button[menuBox_root_id]['sub_button'][id]['url'] = '';
        button[menuBox_root_id]['sub_button'][id]['type'] = 'index';

        key[id] = {};
        key[id]['indextype'] = '';
        
        //父级菜单除name、sub_button 其他设置为空
		button[menuBox_root_id]['key']='';
        button[menuBox_root_id]['type']='';
        button[menuBox_root_id]['url']='';

        key[menuBox_root_id] = '';
		//附加到删除按钮
        $('#jsDelBt').attr('data-id',menuTimes+"_subMenu_"+menuBox_root_id).attr('data-type',2);

	    //默认选中平台模块
	    $('input[name=docInlineRadio][type=radio]').prop('checked',false);
	    $('input[name=docInlineRadio][type=radio][value=index]').prop('checked',true);
	    //移除选中
	    $('input[name=platform][type=radio]').prop('checked',false);

	    //隐藏添加按钮
	    if($(this).parent().siblings('li').length >= 5){
	    	$(this).parent().hide();
	    }
	});


	//删除菜单
	$('#doc-modal-list').find('.am-icon-close').add('#jsDelBt').on('click', function(){
		var id = $(this).attr('data-id');
		var type = $(this).attr('data-type');
		$('#del_alert').text('删除后“'+$('#'+id).children().children('.js_l'+type+'Title').text()+'”菜单下设置的内容将被删除');
      	$('#my-confirm').modal({
        	relatedTarget:this,
        	onConfirm: function() {
          		var id = $(this.relatedTarget).attr('data-id');
          		var type = $(this.relatedTarget).attr('data-type');
          		if(type == 1){
          			//清空要删除的菜单和key
          			button[id] = '';
          			//删除当前菜单下的子菜单信息
          			var subMenu = $('#'+id).find('.sub_pre_menu_list').children('.jslevel2');
          			var subMenuLength = subMenu.length;
          			var subMenuId;
          			if(subMenuLength>0){
          				for(var i=0;i<subMenuLength;i++){
          					subMenuId = subMenu.eq(i).attr('id');
          					key[subMenuId] = '';
          				}
          			}else{
          				key[id] = '';
          			}
          			//根据长度修改样式
          			var menuLength = $('#'+id).siblings('.jsMenu').length;

          			if(menuLength == 2){
          				$('.js_addMenuBox_root').show();
          				$('.jsMenu').addClass('size1of3');
          			}else if(menuLength == 1){
          				$('.js_addMenuBox_root').show();
          				$('.jsMenu').removeClass('size1of3');
          				$('.jsMenu').addClass('size1of2');
          			}else{
          				$('.js_addMenuBox_root').show();
          				$('#menuList').addClass('no_menu');
          				$('.tools_box').hide();
          			}
          		}else if(type == 2){//子菜单

          			var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
          			button[parentId]['sub_button'][id] = '';
          			key[id] = '';
          			var subMenuLength = $('#'+id).siblings('.jsSubMenu').length;
          			//显示子菜单添加按钮
          			if(subMenuLength <= 4){
          				$('#'+id).siblings('.js_addMenuBox').show();
          			}
          			//删除至无子菜单
          			if(subMenuLength == 0){
          				button[parentId]['type'] = 'index';
          				button[parentId]['sub_button'] = {};
          				key[parentId] = {};
          				key[parentId]['indextype'] = '';
          			}
          		}
          		
          		$('#'+id).remove();
          		$('.menu_set_area').hide();
          		$('.warning,#saveMenu').show();
          	}

      	});
    });


	//菜单名称输入框
	$('.js_menu_name').blur(function(){

		$('.js_titlenoTips,.js_titleEorTips').hide();

		var id = $('#jsDelBt').attr('data-id');
		var type = $('#jsDelBt').attr('data-type');
		var menuName = $.trim($(this).val());

		//名称为空
		if(menuName == ''){
			$('.js_titlenoTips').show();
			return false;
		}
		//strlength()自定义函数获取字符串长度，中文为2字节
		var nameLen = strlength(menuName);

		if(type == 1){
			if(nameLen>8){
				$('.js_titlenoTips').hide();
				$('.js_titleEorTips').show();
				return false;
			}else{
				button[id]['name'] = menuName;
			}
		}else{
			if(nameLen>16){
				$('.js_titlenoTips').hide();
				$('.js_titleEorTips').show();
				return false;
			}else{
				var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
				button[parentId]['sub_button'][id]['name'] = menuName;
			}
		}
		$('#'+id).children().children('.js_l'+type+'Title').html(menuName);
		$('.global_info').html(menuName);
	});


	//单选框
	$('input[name=docInlineRadio][type=radio]').change(function(){

		$('.menu_content_container').css('border-color','#e7e7eb');
		$('#menu_tips,.false_url').hide();
		//当前菜单ID及菜单类型
		var id = $('#jsDelBt').attr('data-id');
		var type = $('#jsDelBt').attr('data-type');

		if(type == 2){
			var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
		}
		//当前选中
		var menutype = $(this).val();

		if(type == 1){
			button[id]['type'] = menutype;
		}else if(type == 2){
			button[parentId]['sub_button'][id]['type'] = menutype;
		}

		//根据menutype的值显示配置
		if(menutype == 'click'){
			$('#edit,.menu_content_container').show();
			$('#url,#platform,.tab_content').hide();
			$('.tab_nav').removeClass('selected');
			clickType(id);
		}else if(menutype == 'view'){

			$('#edit,#platform').hide();
			$('#url,.menu_content_container').show();
			if(type == 1){
				$('#urlText').val(button[id]['url']);
			}else if(type == 2){
				var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
				$('#urlText').val(button[parentId]['sub_button'][id]['url']);
			}

		}else if(menutype == 'index'){
			if(!key[id]){
				key[id] = {};
				key[id]['indextype'] = '';
			}
			
			if(!key[id]['indextype']){
				key[id]['indextype'] = '';
			}

			$('#edit,#url').hide();
			$('#platform,.menu_content_container').show();
			$('input[name=platform][type=radio]').prop('checked',false);
			if(key[id]['indextype']){
				$('input[name=platform][type=radio][value='+key[id]['indextype']+']').click();
			}
		}
	});

	//地址输入框
	$('#urlText').blur(function(){
		var url = $.trim($(this).val());
		if(url == ''){
			return false;
		}else{
			var check = url.match(/^((http|https):\/\/)/);
			if(check == null){
				$('.false_url').show();
				return false;
			}else{
				//当前菜单ID及菜单类型
				var id = $('#jsDelBt').attr('data-id');
				var type = $('#jsDelBt').attr('data-type');
				if(type == 1){
					button[id]['url'] = url;
				}else if(type == 2){
					var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
					button[parentId]['sub_button'][id]['url'] = url;
				}
			}
		}
	});

	$('#urlText').keydown(function(){
		$('.menu_content_container').css('border-color','#e7e7eb');
		$('#menu_tips,.false_url').hide();
	});

	//素材选择
	$('.tab_nav a').click(function(){

		$('.menu_content_container').css('border-color','#e7e7eb');
		$('#menu_tips').hide();

		$('.tab_nav').removeClass('selected');
		$(this).parent('.tab_nav').addClass('selected');
		var content = $(this).parent('.tab_nav').attr('data-tab');
		$('.tab_content').hide();
		$(''+content+'').parent('.tab_content').show();

		var id = $('#jsDelBt').attr('data-id');
		var type = $('#jsDelBt').attr('data-type');

		if(type == 2){
			var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
		}
		var keyType = $(this).parent('.tab_nav').attr('data-type');

		key[id]['keytype'] = keyType;
		clickType(id);

	});
	//删除CLICK已选素材
	$('.media_del').click(function(){

		var id = $('#jsDelBt').attr('data-id');
		var type = $('#jsDelBt').attr('data-type');

		$(this).hide();
		var keytype = $(this).attr('data-type');

		if(keytype == 3){
			key[id]['newsMedia_id'] = '';
			key[id]['news_item'] = '';
			key[id]['news_count'] = '';
			key[id]['content'] = '';

			$('.media_cover').show();
			$('.news_show,.news_del').hide();
			$('.news_show').html('');
		}else if(keytype == 2){

			$('.image_cover').show();
			$('.image_show').hide();
			$('.image_show').html('<div class="waiting"><i class="am-icon-refresh am-icon-spin am-icon-md"></i> 上传中,请稍候</div>');

			key[id]['imageUrl'] = '';
			key[id]['imageMedia_id'] = '';

		}

		if(type == '2'){
			var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
			button[parentId]['sub_button'][id]['key'] = '';
					
		}else{
			button[id]['key'] = '';
		}
		
	});

	//
	$('#menuList').on('click','.jslevel1 .pre_menu_link',function(){

		var id = $(this).parent('.jslevel1').attr('id');
		
		//更改页面,隐藏提示,修改提示语
		$('.menu_set_area,#saveMenu,.js_titleNolTips').show();//显示设置项
		$('.menu_content_container').css('border-color','#e7e7eb');
		$('#menu_tips,.false_url,.warning,.js_titlenoTips,.js_titleEorTips,.js_titleNolTipsSubButton').hide();
		
		$('#jsDelBt').text('删除菜单');
	    $('.global_info').html($(this).children('.js_l1Title').html());
	    $('.js_menuTitle').text('菜单名称');
	    $('.js_menuContent').text('菜单内容');
	    $('.js_menu_name').val($(this).children('.js_l1Title').html()).focus().select();
	    //附加到删除按钮
	    $('#jsDelBt').attr('data-id',id).attr('data-type',1);

	    //修改样式
	    $('.jslevel1,.jslevel2').removeClass('current selected');
	    $(this).parent('.jslevel1').addClass('current selected');
	    //子菜单
	   	$('.jslevel1').children('.sub_pre_menu_box').hide();
	   	$(this).siblings('.sub_pre_menu_box').show();
	  	//判断是否存在子菜单
	  	if($(this).siblings('.sub_pre_menu_box').children().children('li').length != 1){
	  		//存在
	  		$('.frm_control_group,.menu_content_container').hide();
	  		$('#js_innerNone,.js_setNameBox').show();
	  	}else{
	  		//不存在
	  		$('#js_innerNone').hide();
	  		$('.frm_control_group,.menu_content_container').show();

	  		var type = button[id]['type'];

	  		$('input[name=docInlineRadio][type=radio]').prop('checked',false);
	  		$('input[name=docInlineRadio][type=radio][value='+type+']').prop('checked',true);

	  		if(type == 'click'){
	  			//显示菜单设置项
				$('#edit').show();
				$('#url,#platform,.tab_content').hide();
				//重置
		  		$('.tab_nav').removeClass('selected');
				clickType(id);
	  		}else if(type == 'view'){

	  			$('#url').show();//显示菜单设置项
				$('#edit,#platform').hide();
				$('#urlText').val(button[id]['url']);

	  		}else if(type == 'index'){
	  			$('#platform').show();//显示菜单设置项
				$('#edit,#url').hide();

				$('input[name=platform][type=radio]').prop('checked',false);
				if(typeof(key[id]['indextype']) != undefined){
					$('input[name=platform][type=radio][value="'+key[id]['indextype']+'"]').prop('checked',true);
				}
	  		}
	  	}
	});

	//子菜单
	$('#menuList').on('click','.jslevel2 a',function(){
		//获取ID
		var id = $(this).parent('.jslevel2').attr('id');
		var parentId = $(this).parent().parent().parent().parent('.jslevel1').attr('id');

		$('.jslevel1').children('.sub_pre_menu_box').hide();
		$('#'+parentId).children('.sub_pre_menu_box').show();

		//更改页面,隐藏提示
		$('#urlText').val('');
		$('#js_innerNone,#menu_tips,.false_url,.js_titlenoTips,.js_titleEorTips,.warning').hide();
		$('.frm_control_group,.menu_content_container,.menu_set_area,#saveMenu').show();
		$('.menu_content_container').css('border-color','#e7e7eb');

		$('#jsDelBt').html('删除子菜单');
	    $('.global_info').html($(this).children('.js_l2Title').html());
	    $('.js_menuTitle').html('子菜单名称');
	    $('.js_menuContent').html('子菜单内容');
	    $('.js_menu_name').val($(this).children('.js_l2Title').html()).focus().select();;

	    //附加到删除按钮
	    $('#jsDelBt').attr('data-id',id).attr('data-type',2);
	    //修改提示语
	    $('.js_titleNolTipsSubButton').show();
	    $('.js_titleNolTips').hide();
	    //修改样式
	    $('.jslevel1,.jslevel2').removeClass('current selected');
	    $(this).parent('.jslevel2').addClass('current selected');
	    
	    var type = button[parentId]['sub_button'][id]['type'];
	   
	   	$('input[name=docInlineRadio][type=radio]').prop('checked',false);
	    $('input[name=docInlineRadio][type=radio][value='+type+']').prop('checked',true);
	    
	    if(type == 'view'){
	   		//显示菜单设置项
			$('#edit,#platform').hide();
			$('#url').show();
	    	$('#urlText').val(button[parentId]['sub_button'][id]['url']);
	    }else if(type == 'click'){
	    	$('#url,#platform,.tab_content').hide();//显示菜单设置项
			$('#edit').show();
			//重置
	    	$('.tab_nav').removeClass('selected');
			clickType(id);
	    }else if(type == 'index'){
	    	$('#platform').show();//显示菜单设置项
			$('#edit,#url').hide();

			$('input[name=platform][type=radio]').prop('checked',false);
			if(typeof(key[id]['indextype']) != undefined){
				$('input[name=platform][type=radio][value="'+key[id]['indextype']+'"]').prop('checked',true);
			}
	    }
	});

	//选择图文素材
	$('#edit_news').click(function(){
		$('.menu_content_container').css('border-color','#e7e7eb');
		$('#menu_tips').hide();

		var news = $('.choose').html();
		//media_id
		var newsMedia_id = $('.choose').attr('data-id');
		$('.news_cover').hide();
		$('.news_show').html('<div class="appmsg_content">'+news+'</div>');
		$('.news_show,.news_del').show();

		var id = $('#jsDelBt').attr('data-id');
		var type = $('#jsDelBt').attr('data-type');

		var times = new Date().getTime();
		key[id]['newsMedia_id'] = newsMedia_id;
		key[id]['newskey'] = 'V003_'+times+'_NEWS';
		key[id]['content'] = $('.news_show').html();
		key[id]['keytype'] = 3;

		if(type == 2){
			var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
			button[parentId]['sub_button'][id]['key'] = 'V003_'+times+'_NEWS';
		}else{
			button[id]['key'] = 'V003_'+times+'_NEWS';
		}
		
	});

	//选择图片素材
	$('#edit_image').click(function(){
		$('.menu_content_container').css('border-color','#e7e7eb');
		$('#menu_tips').hide();

		var image_url = $('.choose_image').attr('src');
		var media_id = $('.choose_image').attr('data-id');

		$('.image_cover').hide();
		$('.image_show,.image_del').show();
		$('.image_show').html('<img src="'+image_url+'" class="material_image"/>');

		var id = $('#jsDelBt').attr('data-id');
		var type = $('#jsDelBt').attr('data-type');
		var times = new Date().getTime();

		key[id]['imageUrl'] = image_url;
		key[id]['imageMedia_id'] = media_id;
		key[id]['imagekey'] = 'V002_'+times+'_IMAGE';
		key[id]['keytype'] = 2;

		if(type == '2'){
			var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
			button[parentId]['sub_button'][id]['key'] = 'V002_'+times+'_IMAGE';				
		}else{
			button[id]['key'] = 'V002_'+times+'_IMAGE';
		}

	});

	$('#editor1').blur(function(){
		var id = $('#jsDelBt').attr('data-id');
		var type = $('#jsDelBt').attr('data-type');

		var content = $(this).val();
		if(content == "<br>" || content == '' || content == '<div><br></div>'){
			$(this).val('');
			content = '';
			if(type == 2){
				var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
				button[parentId]['sub_button'][id]['key'] = '';
			}else{
				button[id]['key'] = '';
			}
		}else{
			var times=new Date().getTime();
			key[id]['textkey'] = 'V001_'+times+'_TEXT';
			if(type == 2){
				var parentId = $('#'+id).parent().parent().parent('.jslevel1').attr('id');
				button[parentId]['sub_button'][id]['key'] = 'V001_'+times+'_TEXT';
			}else{
				button[id]['key'] = 'V001_'+times+'_TEXT';
			}
		}
		key[id]['text'] = content;	
		key[id]['keytype'] = 1;							
	});
	
});



//------------------------------------------------------------------------------------->方法
function clickType(id){
	var show;
	if(key[id]['keytype'] == 3){
	//选中图文
		$('.tab_appmsg').addClass('selected');
		show = $('.tab_appmsg').attr('data-tab');

		if(key[id]['newsMedia_id'] != undefined && key[id]['newsMedia_id'] != ''){
			if(!key[id]['content']){
				if(key[id]['news_count']>1){
					var str = '<div class="appmsg_content"><div class="appmsg_info"><em class="appmsg_date"></em></div>';
					for(var i=0;i<key[id]['news_count'];i++){
						if(i == 0){
							str += '<div class="cover_appmsg_item"><h4 class="appmsg_title js_title"><a href="javascript:void(0);">'+key[id]['news_item'][i]['title']+'</a></h4><div class="appmsg_thumb_wrp" style="background-image:url('+gTencentPicUrl+key[id]['news_item'][i]['thumb_url']+')"></div></div>';
						}else{
							str += '<div class="appmsg_item has_cover"><h4 class="appmsg_title js_title"><a href="javascript:void(0);">'+key[id]['news_item'][i]['title']+'</a></h4><div class="appmsg_thumb_wrp" style="background-image:url('+gTencentPicUrl+key[id]['news_item'][i]['thumb_url']+')"></div></div>';
						}
					}
					str += '</div>';
					$('.news_show').html(str);
				}else{
					$('.news_show').html('<div class="appmsg_content"><div class="appmsg_info"><em class="appmsg_date"></em></div><div class="appmsg_item"><h4 class="appmsg_title js_title">'+key[id]['news_item'][0]['title']+'</h4><div class="appmsg_thumb_wrp" style="background-image:url('+gTencentPicUrl+key[id]['news_item'][0]['thumb_url']+')"></div><p class="appmsg_desc">'+key[id]['news_item'][0]['digest']+'</p></div></div>');
				}
				key[id]['content'] = $('.news_show').html();
			}else{
				$('.news_show').html(key[id]['content']);
			}
			$('.news_cover').hide();
			$('.news_del,.news_show').show();
		}else{
			$('.news_cover').show();
			$('.news_show,.news_del').hide();
		}
					
	}else if(key[id]['keytype'] == 2){
		$('.tab_img').addClass('selected');
		show = $('.tab_img').attr('data-tab');
		if(key[id]['imageMedia_id'] != undefined && key[id]['imageMedia_id'] != ''){
			$('.image_cover').hide();
			$('.image_show,.image_del').show();
			$('.image_show').html('<img src="'+gTencentPicUrl+key[id]['imageUrl']+'" class="material_image"/>');
		}else{
			$('.image_cover').show();
			$('.image_show,.image_del').hide();
			$('.image_show').html('<div class="waiting"><i class="am-icon-refresh am-icon-spin am-icon-md"></i> 上传中,请稍候</div>');
		}
	}else if(key[id]['keytype'] == 1){
		$('.tab_text').addClass('selected');
		show = $('.tab_text').attr('data-tab');
		if(key[id]['text'] != undefined && key[id]['text'] != ''){
			$('.wysiwyg-editor').html(key[id]['text']);
		}else{
			$('.wysiwyg-editor').html('');
		}
	}else{
		$('.tab_appmsg').addClass('selected');
		show = $('.tab_appmsg').attr('data-tab');
		$('.news_cover').show();
		$('.news_show,.news_del').hide();
	}
	$(show).parent('.tab_content').show();
}